import { useEffect } from 'react'
import { localCache } from '@/utils/storage'
import { useLocation, useNavigate } from 'react-router-dom'

interface IProp {
	animationDuration?: number
	isFinished?: boolean
	children: any
}

const AuthRoute = ({ children }: IProp) => {
	const navigate = useNavigate()
	const location = useLocation()

	const token = localCache.getItem('token')
	useEffect(() => {
		if (token && location.pathname === '/login') {
			navigate('/login')
		}
	}, [])

	return children
}

export default AuthRoute
